﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Project_02
{
    public partial class Console : Form
    {
        private ToolTip toolTip;
        public Console()
        {
            InitializeComponent();
        }
        private void databaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }
        private void commandTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r') {
                ExecuteCommand(commandTextBox.Text);
                e.Handled = false;
            }
        }
        private Boolean ValidCommand(String command) {
            return false;
        }
        private void ExecuteCommand(String text) {
            try {
                String name = (new Command(text)).GetCommand();
                if (name == "ban") {
                    BanCommand command = new BanCommand(text);
                } else if (name == "silence") {
                    SilenceCommand command = new SilenceCommand(text);
                }
            } catch(Exception e) {
                ShowToolTip(e.Message);
            }
        }
        private void ShowToolTip(String text) {
            toolTip.Active = true;
            toolTip.Show(text, this, 
                         commandTextBox.Bounds.X + 5, 
                         commandTextBox.Bounds.Top + commandTextBox.Bounds.Height + 25, 
                         5 * 1000);   
        }
        private void Console_Load(object sender, EventArgs e)
        {
            toolTip = new ToolTip();
            toolTip.ToolTipIcon = ToolTipIcon.Warning;
            toolTip.ToolTipTitle = "Warning!";
            commandTextBox.Select();
        }
        private void commandTextBox_Leave(object sender, EventArgs e)
        {
            toolTip.Active = false;
        }
        private void commandTextBox_Click(object sender, EventArgs e)
        {
            toolTip.Active = false;
        }
    }
}
